const trigger = (el, type) => {
    const e = document.createEvent('HTMLEvents')
    e.initEvent(type, true, true)
    el.dispatchEvent(e)
};
export default {
    bind (el, binding) {
        if (binding.value === false) {
            return;
        }
        const input = el.getElementsByTagName('input')[0]
        input.oninput = function (e) {
            if (input.value.length === 1) {
                input.value = input.value.replace(/[^0-9]/g, '')
            } else {
                input.value = input.value.replace(/[^\d]/g, '')
            }
            trigger(input, 'oninput')
        }
    }
};
